{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example of get data from ion server\n",
    "#### 1. git clone https://gitee.com/bigduduwxf/neuron-vis.git\n",
    "#### 2. install all the dependence libs \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "d:\\Program Files\\anaconda3\\envs\\neuronVis\\lib\\site-packages\\numpy\\_distributor_init.py:30: UserWarning: loaded more than 1 DLL from .libs:\n",
      "d:\\Program Files\\anaconda3\\envs\\neuronVis\\lib\\site-packages\\numpy\\.libs\\libopenblas.FB5AE2TYXYH2IJRDKGDGQ3XBKLKTF43H.gfortran-win_amd64.dll\n",
      "d:\\Program Files\\anaconda3\\envs\\neuronVis\\lib\\site-packages\\numpy\\.libs\\libopenblas64__v0.3.21-gcc_10_3_0.dll\n",
      "  warnings.warn(\"loaded more than 1 DLL from .libs:\"\n"
     ]
    }
   ],
   "source": [
    "import sys,copy,os,inspect\n",
    "if hasattr(sys.modules[__name__], '__file__'):\n",
    "    _file_name = __file__\n",
    "else:\n",
    "    _file_name = inspect.getfile(inspect.currentframe())\n",
    "CURRENT_FILE_PATH = os.path.dirname(_file_name)\n",
    "sys.path.append(os.getcwd()+\"/../neuronVis\")\n",
    "\n",
    "import IONData "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Get all the samples by project name like \"PFC\"\\\"HIP\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "iondata = IONData.IONData()\n",
    "\n",
    "hipsample = iondata.getSampleInfo(projectID='HIP')\n",
    "# PFCsample = iondata.getSampleInfo(projectID='PFC')\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Get all the neurons from each sample\n",
    "#### All the neurons will be saved into the path '../source/swc/sampleid'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "201733\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/001.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/002.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/003.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/004.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/005.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/007.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/008.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/009.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/011.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/012.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/013.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/014.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/015.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/016.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/017.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/018.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/019.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/020.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/021.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/022.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/023.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/024.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/025.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/026.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/027.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/029.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/030.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/031.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/032.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/033.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/034.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/035.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/036.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/037.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/038.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/039.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/040.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/041.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/042.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/043.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/044.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/045.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/046.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/047.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/048.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/049.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/050.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/051.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/052.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/053.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/054.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/055.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/056.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/057.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/058.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/059.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/060.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/061.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/062.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/063.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/064.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/065.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/066.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/067.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/068.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/069.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/070.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/071.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/072.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/073.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/074.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/075.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/076.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/077.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/078.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/079.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/080.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/081.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/082.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/083.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/084.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/085.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/086.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/087.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/088.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/089.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/090.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/091.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/092.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/093.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/094.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/095.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/096.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/097.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/098.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/099.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/100.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/101.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/102.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/103.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/104.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/105.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/107.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/109.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/110.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/111.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/112.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/113.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/114.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/117.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/118.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/119.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/121.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/122.swc\n",
      "exist  e:\\workspace\\project\\neuron-vis\\analyseCase/../neuronVis/../resource/swc/201733/123.swc\n"
     ]
    }
   ],
   "source": [
    "for sample in hipsample[0:1]:\n",
    "    print(sample['fMOST_id'])\n",
    "    iondata.getNeuronTreeBySampleID(str(sample['fMOST_id']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import BrainRegion as BR \n",
    "import numpy as np\n",
    "br = BR.BrainRegion()\n",
    "br.praseJson()\n",
    "iondata = IONData.IONData()\n",
    "property = iondata.getNeuronPropertyByID('210728', '037.swc')\n",
    "brproperty=BR.RegionProperty(copy.deepcopy(br))\n",
    "brproperty.setProperty(property['projectregion'])\n",
    "brainregion=brproperty.getRegion('FRP')\n",
    "regionsum = brproperty.getSumProperty('FRP')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "regionsum = brproperty.getSumProperty('unknow')\n",
    "print(regionsum)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "iondata = IONData.IONData()\n",
    "neurons = iondata.getNeuronListByProjectBrainRegion('RSP')\n",
    "print(neurons)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(len(neurons))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas \n",
    "df =pandas.DataFrame(neurons)\n",
    "df2 = df.drop_duplicates()\n",
    "print(neurons)\n",
    "# neuronsmap= sorted(neurons)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df2 = df.drop_duplicates()\n",
    "df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df2.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for neuron in df2.values.tolist():\n",
    "    print(neuron)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "neurons = iondata.getNeuronListByProjectBrainRegion('FRP1')\n",
    "print(len(neurons))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import Visual as nv\n",
    "import json\n",
    "import SwcLoader as nt\n",
    "import Scene\n",
    "import IONData\n",
    "neuronvis = nv.neuronVis(size=(1700,1000),renderModel=0)\n",
    "\n",
    "neuronvis.render.setBackgroundColor((1.0,1.0,1.,1.0))\n",
    "# neuronvis.addRegion('CLA',[0.5,1.0,0.5])\n",
    "\n",
    "iondata = IONData.IONData()\n",
    "neuronlist = iondata.getNeuronListBySampleID('221612')\n",
    "\n",
    "neuronvis.setLineWidth(2)\n",
    "\n",
    "neuronvis.addNeuronByList(neuronlist[1:3],mirrorToRight=True,isLine=True,somaRadius=500)\n",
    "\n",
    "# neuronvis.render.savepng('../resource/testwxf.png')\n",
    "# neuronvis.clear(root=True,neurons=False)\n",
    "neuronvis.render.setView()\n",
    "# neuronvis.render.animation(90*0)\n",
    "neuronvis.render.run()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "neuronVis",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
